#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MAXN 200010
int t,n,a[MAXN];
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>t;
	while(t--){
		cin>>n;
		for(int i=1;i<=n;++i) cin>>a[i];
		if(n<=15){
			ll ans=0;
			vector<bool>vh(n+1,false);
			for(int base=0;base<(1<<n);++base){
				for(int i=0;i<n;++i) vh[i+1]=(base>>i)&1;
				ll num=0;
				for(int i=1;i<=n;++i)for(int j=i-1;j>=1;--j)if(vh[i]==vh[j]){
					num+=(a[i]==a[j])*a[i];
					break;
				}ans=max(ans,num);
			}cout<<ans<<endl;
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}